{	Problem: http://codeforces.ru/problemset/problem/2/A
	Verdict: Accepted
}
uses sysutils;
type player=record
    n:string;
    p,s:longint;
    t:array[1..1010,1..2] of longint;
end;
var a:array[0..1010] of player; i,n,k,j,index,m,c,cur:longint; s,t:string;
begin
readln(n);
k:=0;
for i:=1 to n do begin
    readln(s);
    t:=copy(s,1,pos(' ',s)-1);
    delete(s,1,pos(' ',s));
    index:=0;
    for j:=1 to k do 
        if a[j].n=t then index:=j;
    if index=0 then begin
        inc(k);
        index:=k;
        a[k].n:=t;
    end;
    inc(a[index].p,strtoint(s));
    inc(a[index].s);
    a[index].t[a[index].s][1]:=i;
    a[index].t[a[index].s][2]:=a[index].p;
end;
m:=1;
i:=0;
while i<a[1].s do begin
  inc(i);
  if a[1].t[i][2]>=a[1].p then begin
    c:=a[1].t[i][1];
    i:=maxlongint;
  end;
end;
for i:=2 to k do
    if a[i].p>a[m].p then begin
      m:=i;
      c:=0;
      for j:=1 to a[i].s do
        if a[i].t[j][2]>=a[i].p then begin
          c:=a[i].t[j][1];
          break;
        end;
    end else
    if (a[i].p=a[m].p) then begin
      cur:=0;
      for j:=1 to a[i].s do
        if a[i].t[j][2]>=a[i].p then begin
          cur:=a[i].t[j][1];
          break;
        end;
      if cur<c then begin
        c:=cur;
        m:=i;
      end;
    end;
write(a[m].n);
end.